package com.product.server.controller;

import com.product.server.model.ProductInfo;
import com.product.server.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService ;

    // 根据 url来获取参数
    @RequestMapping("/{productId}")
    public ProductInfo getProductInfo(@PathVariable("productId") Integer productId){
        return productService.getById(productId);
    }

    // 传递一个或多个参数
    @RequestMapping("/p1")
    public String p1(Integer id , String name){
        return "p1: id: "+id + "name:"+name ;
    }

    // 传递对象

    @RequestMapping("/p2")
    public String p2(ProductInfo productInfo){
        return "p2: "+productInfo.toString();
    }

    // 传递json
    @RequestMapping("/p3")
    public String p3(@RequestBody ProductInfo productInfo){
        return "p3: "+ productInfo.toString() ;
    }

}
